package com.chen.common.log;

import com.chen.common.consts.Const;

import java.io.IOException;
import java.util.logging.*;

/**
 * @author ex_chenzy59
 * @since 2025/2/28
 */
@Deprecated
public class Log {
    private static final Logger logger = Logger.getLogger(Log.class.getName());

    public void hello() {
        // 创建文件处理器，将日志输出到文件
        try {
            //D:\%Y-%m-%D-app-%H.log
            var filePath="D:/log/app.log";

            filePath="D:/log_%m.log";
//            filePath="D:/app_%m.log";
//            var fileHandler = new FileHandler(filePath,1024,100,true);
            var fileHandler = new FileHandlerMy(filePath,1024,100,true);
            fileHandler.setLevel(Level.INFO);
            fileHandler.setFormatter(new SimpleFormatter());
            fileHandler.setEncoding(Const.charset.name());
//            fileHandler.setFormatter(new Formatter() {
//                @Override
//                public String format(LogRecord record) {
//                    return null;
//                }
//            });
            // 添加处理器到日志记录器
            logger.addHandler(fileHandler);
//            logger.addHandler(new ConsoleHandler());
            // 设置日志级别
            logger.setLevel(Level.ALL);
            // 记录不同级别的日志
            logger.severe("This is a severe message11231232");
            logger.warning("This is a warning message2");
            logger.info("This is an info message3");
            logger.config("This is a config message");
            logger.fine("This is a fine message");
            logger.finer("This is a finer message");
            logger.finest("This is a finest message");
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Exception occurred", e);
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        new Log().hello();
    }
}
